//---------------------------------------------------------------------
// Copyright (C) 2010 - Cobalt Solution / Sebastien Leon              |
//---------------------------------------------------------------------
// This software is under dual licence: commercial licence + GPL v3   |
// To keep closed your modification of this software, you need to     |
// contact me to obtain a commercial licence.                         |
// Any other derivated work should remain Open Source.                |
// Contact me for a licence, a question or if you want to commit      |
// your code to the main tree: seb at cobaltsolutions dot info        |
//---------------------------------------------------------------------

#ifndef _FTPTHREAD_H_
#define _FTPTHREAD_H_

#include <QThread>
#include <QFile>
#include <QFtp>

class Loom;
class Core;

class FTPThread : public QThread
{
  Q_OBJECT
public:
  FTPThread(Core& core, Loom& loom, int fileToUpload);
  virtual void run();

  Loom&   GetLoom () { return mr_loom;  }
  int     GetResID() { return m_fileID; }
  const QString GetTargetName() const;

  bool TransferOk () { return m_ok; }
private:
  Core&   mr_core;
  Loom&   mr_loom;
  QFtp    m_ftp;
  QFile   m_src;
  int     m_fileID;
  bool    m_ok;

  QString MsgTitle();
  void AbortTransfer();
protected slots:
  void Terminated             ();
  void TimeOut                ();
  void FtpCommandFinished     (int,    bool  );
  void FtpDataTransferProgress(qint64, qint64);
  void Done (bool);

signals:
  void ThisTerminated  (FTPThread&);
  //void TransferProgress(Loom& l, int res, float progress);
  void TransferInProgress (const int, const QString& name, const float progress);
};

#endif _FTPTHREAD_H_
